package com.cloud.drore.eboss.supplier.service.impl;

import com.cloud.drore.eboos.common.base.*;
import com.cloud.drore.eboos.common.constant.ResultCodeConstant;
import com.cloud.drore.eboos.common.entity.base.DictionaryVo;
import com.cloud.drore.eboos.common.entity.operation.po.GetProductByOTARequest;
import com.cloud.drore.eboos.common.entity.supplier.ProductRelation;
import com.cloud.drore.eboos.common.entity.supplier.Ticket;
import com.cloud.drore.eboos.common.entity.supplier.TicketPrice;
import com.cloud.drore.eboos.common.entity.supplier.TicketStock;
import com.cloud.drore.eboos.common.entity.supplier.po.TicketQueryPo;
import com.cloud.drore.eboos.common.entity.supplier.vo.TicketAllVo;
import com.cloud.drore.eboos.common.entity.supplier.vo.TicketVo;
import com.cloud.drore.eboos.common.util.CodingGeneration;
import com.cloud.drore.eboos.common.util.DateToStringUtil;
import com.cloud.drore.eboos.common.util.LocalData;
import com.cloud.drore.eboos.common.util.LocalDateAndDateTransformUtil;
import com.cloud.drore.eboos.exception.BusinessException;
import com.cloud.drore.eboss.login.feign.ILoginFeign;
import com.cloud.drore.eboss.login.feign.ShiroUserVo;
import com.cloud.drore.eboss.operation.entity.ConsumeOperation;
import com.cloud.drore.eboss.operation.entity.POIOperation;
import com.cloud.drore.eboss.operation.entity.po.SupplierSettlementAutoInfoPo;
import com.cloud.drore.eboss.operation.supplierApiService.IConsumeSupplierApiService;
import com.cloud.drore.eboss.operation.supplierApiService.IMerchantSupplierApiService;
import com.cloud.drore.eboss.operation.supplierApiService.IPOISupplierApiService;
import com.cloud.drore.eboss.supplier.entity.CombinationProduct;
import com.cloud.drore.eboss.supplier.entity.ProductConsumeRelation;
import com.cloud.drore.eboss.supplier.entity.ProductRejectInfo;
import com.cloud.drore.eboss.supplier.entity.ProductValidateMethod;
import com.cloud.drore.eboss.supplier.entity.po.GetProductByOTAResponsePo;
import com.cloud.drore.eboss.supplier.entity.po.ProductInfoResponseComparePo;
import com.cloud.drore.eboss.supplier.entity.po.ProductInfoResponsePo;
import com.cloud.drore.eboss.supplier.entity.po.SupplierTicketUpdPo;
import com.cloud.drore.eboss.supplier.entity.vo.DictionaryTicketVo;
import com.cloud.drore.eboss.supplier.entity.vo.ProductRejectInfoVo;
import com.cloud.drore.eboss.supplier.mapper.*;
import com.cloud.drore.eboss.supplier.service.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import static com.cloud.drore.eboos.common.constant.CommonConstant.TO_BE_ON_THE_SHELVES;

/**
 * 浙江卓锐科技股份有限公司 版权所有  Copyright 2018<br>
 *
 * @Description: <br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/1/8 10:41 <br>
 * @Author: <a href="575842778@qq.com">郑永涛</a>
 */
@Service
public class TicketServiceImpl extends BaseServiceImpl implements ITicketService {

    @Autowired
    TicketMapper ticketMapper;
    @Autowired
    TicketStockMapper ticketStockMapper;
    @Autowired
    TicketPriceMapper ticketPriceMapper;
    @Autowired
    IBaseDataFeign baseDataFeign;
    @Autowired
    IConsumeFeign consumeFeign;
    @Autowired
    ProductRelationMapper productRelationMapper;
    @Resource
    SupplierSettlementAutoInfoMapper supplierSettlementAutoInfoMapper;
    @Resource
    IConsumeSupplierApiService consumeSupplierApiService;
    @Resource
    IPOISupplierApiService ipoiSupplierApiService;
    @Resource
    IMerchantSupplierApiService merchantSupplierApiService;
    @Resource
    IDistributorProductAssociationService distributorProductAssociationService;
    @Autowired
    ProductConsumeRelationMapper productConsumeRelationMapper;
    @Autowired
    ProductValidateMethodMapper productValidateMethodMapper;
    @Autowired
    IBaseDataFeign iBaseDataFeign;
    @Autowired
    ProductRejectInfoMapper productRejectInfoMapper;
    @Resource
    ICYTGetProductFeign getProductFeign;
    @Resource
    IProductStockService productStockService;
    @Autowired
    ProductStockMapper productStockMapper;
    @Autowired
    CombinationProductRelationMapper combinationProductRelationMapper;
    @Autowired
    CombinationProductMapper combinationProductMapper;

    static final String TICKET_UPDATE_SUCESS = "门票信息更新成功!";
    static final String TICKET_UPDATE_FAILURE = "门票信息更新失败!";
    static final String TICKET_QUERY_FAILURE = "门票信息查询失败!";
    static final String TICKET_SAVE_FAILURE = "门票信息保存失败!";
    static final String TICKET_RELATE_FAILURE = "门票关联分销商失败!";
    static final int BUSINESS_CODE = 8203;
    static final String COMBINATION_PRODUCT = "COMBINATION_PRODUCT";
    static final String TICKET_PRODUCT = "TICKET_PRODUCT";
    static final String DICTIONARY_STATUS_TRUE = "1";
    static final String DICTIONARY_STATUS_FALSE = "0";
    static final String TO_BE_AUDITED = "TO_BE_AUDITED";
    static final String TICKET_PRODUCT_CH_NAME = "门票产品";
    static final String UNLIMITED_STOCK = "UNLIMITED_STOCK";
    static final String NOT_REFUNDABLE = "NOT_REFUNDABLE";
    static final String NO_CHARGES = "NO_CHARGES";
    private final Log logger = LogFactory.getLog(getClass());
    static final String PRODUCT_NUM_PREFIX = "TP";
    static final String THE_SHELVES = "THE_SHELVES";
    private static String AVAILABLE_FOR_NO_CONSUMPTION = "AVAILABLE_FOR_NO_CONSUMPTION";
    private static String CYCLICAL_INVENTORY = "CYCLICAL_INVENTORY";
    private static String MERCHANT_SUPPLIER = "MERCHANT_SUPPLIER";
    private static String EXPIRED = "EXPIRED";

    @Override
    public MyMapper getMapper() {
        return ticketMapper;
    }

    /**
     * @param pagePo
     * @ClassName: TicketServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 门票信息分页查询运营商接口
     * @CreateDate: Created in 2018/1/16 17:29
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public PageInfo findTicketByParam(PagePo<TicketQueryPo> pagePo) throws BusinessException {
        return new PageInfo(findTicketListByParam(pagePo));
    }

    /**
     * @param pagePo
     * @ClassName: TicketServiceImpl
     * @Return: java.util.List<com.cloud.drore.eboos.common.entity.supplier.vo.TicketAllVo>
     * @Decription: 供应商分页查询门票接口
     * @CreateDate: Created in 2018/3/6 10:14
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public List<TicketAllVo> findTicketByParamSupplier(PagePo<TicketQueryPo> pagePo) throws BusinessException {

        //根据门票po查询门票数据
        TicketQueryPo ticketQueryPo = pagePo.getFields();
        //查询有当前供应商参与的组合产品
        ticketQueryPo.setSupplierId(Long.valueOf(LocalData.getCurrentUser().getTypeId()));
        pagePo.setFields(ticketQueryPo);
        PageHelper.startPage(pagePo);
        List<TicketAllVo> ticketList = ticketMapper.findTicketByParam(pagePo.getFields());
        //设置消费点名称和poi名称
        ticketList.stream().map(ticketStream -> {
            ConsumeOperation consume = (ConsumeOperation) consumeSupplierApiService.selectByPrimaryKey(ticketStream.getConsumeId());
            if (consume != null) {
                ticketStream.setPoiName(consume.getConsumePoiName());
                ticketStream.setConsumeName(consume.getConsumeName());
            }
            if (StringUtils.isNotBlank(ticketStream.getStockMethod())) {
                DictionaryVo stockDic = baseDataFeign.getDictionaryVo(ticketStream.getStockMethod());
                ticketStream.setStockMethod(stockDic == null ? "" : stockDic.getName());
            }

            //设置产品类型为门票类型
            ticketStream.setProductType(TICKET_PRODUCT_CH_NAME);
            return ticketStream;
        }).collect(Collectors.toList());
        return ticketList;
    }


    /**
     * @param pagePo
     * @ClassName: TicketServiceImpl
     * @Return: java.util.List<com.cloud.drore.eboos.common.entity.supplier.vo.TicketAllVo>
     * @Decription: 门票信息分页查询 分销商接口
     * @CreateDate: Created in 2018/1/24 16:10
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public List<TicketAllVo> findTicketByParamDealer(PagePo<TicketQueryPo> pagePo) throws BusinessException {
        //根据门票po查询门票数据
        TicketQueryPo ticketQueryPo = pagePo.getFields();
        ticketQueryPo.setStatus(THE_SHELVES);
        pagePo.setFields(ticketQueryPo);
        PageHelper.startPage(pagePo);
        List<TicketAllVo> ticketList = ticketMapper.findTicketByParam(pagePo.getFields());
        //设置消费点名称和poi名称
        ticketList.stream().map(ticketStream -> {
            ConsumeOperation consume = (ConsumeOperation) consumeSupplierApiService.selectByPrimaryKey(ticketStream.getConsumeId());
            if (consume != null) {
                //设置poiId
                ticketStream.setPoiId(consume.getConsumePoiId());
                ticketStream.setPoiName(consume.getConsumePoiName());
                ticketStream.setConsumeName(consume.getConsumeName());
                if (StringUtils.isNotBlank(ticketStream.getCrowd())) {
                    DictionaryVo crowdDic = baseDataFeign.getDictionaryVo(ticketStream.getCrowd());
                    ticketStream.setCrowd(crowdDic == null ? "" : crowdDic.getName());
                }
                if (StringUtils.isNotBlank(ticketStream.getStockMethod())) {
                    DictionaryVo stockDic = baseDataFeign.getDictionaryVo(ticketStream.getStockMethod());
                    ticketStream.setStockMethod(stockDic == null ? "" : stockDic.getName());
                }
            }
            if (ticketStream.getRefundModel() != null) {
                DictionaryVo refundDictionary = baseDataFeign.getDictionaryVo(ticketStream.getRefundModel());
                if (refundDictionary != null) {
                    ticketStream.setRefundModel(refundDictionary.getName());
                }
            }

            //设置产品验证方式
            ProductValidateMethod validateMethod = new ProductValidateMethod();
            validateMethod.setProductId(ticketStream.getTicketId());
            validateMethod.setProductType(TICKET_PRODUCT);
            validateMethod.setState(DICTIONARY_STATUS_TRUE);
            List<ProductValidateMethod> validateMethodDb = productValidateMethodMapper.selectValidateMethodByParam(validateMethod);
            List<String> validateMethodDbCode = new ArrayList<>();
            validateMethodDbCode = validateMethodDb.stream().map(ProductValidateMethod::getDicCode).collect(Collectors.toList());
            ticketStream.setVerificationType(validateMethodDbCode);

            //设置产品类型为门票类型
            ticketStream.setProductType(TICKET_PRODUCT_CH_NAME);
            return ticketStream;
        }).collect(Collectors.toList());
        return ticketList;
    }

    /**
     * @param pagePo
     * @ClassName: TicketServiceImpl
     * @Return: java.util.List<com.cloud.drore.eboos.common.entity.supplier.vo.TicketAllVo>
     * @Decription: 根据条件分页查询门票信息
     * @CreateDate: Created in 2018/2/24 10:45
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    private List<TicketAllVo> findTicketListByParam(PagePo<TicketQueryPo> pagePo) throws BusinessException {
        //根据门票po查询门票数据
        PageHelper.startPage(pagePo);
        List<TicketAllVo> ticketList = ticketMapper.findTicketByParam(pagePo.getFields());
        //设置消费点名称和poi名称
        ticketList.stream().map(ticketStream -> {
            ConsumeOperation consume = (ConsumeOperation) consumeSupplierApiService.selectByPrimaryKey(ticketStream.getConsumeId());
            if (consume != null) {
                ticketStream.setPoiName(consume.getConsumePoiName());
                ticketStream.setConsumeName(consume.getConsumeName());
                if (StringUtils.isNotBlank(ticketStream.getCrowd())) {
                    DictionaryVo crowdDic = baseDataFeign.getDictionaryVo(ticketStream.getCrowd());
                    ticketStream.setCrowd(crowdDic == null ? "" : crowdDic.getName());
                }
                if (StringUtils.isNotBlank(ticketStream.getStockMethod())) {
                    DictionaryVo stockDic = baseDataFeign.getDictionaryVo(ticketStream.getStockMethod());
                    ticketStream.setStockMethod(stockDic == null ? "" : stockDic.getName());
                }
            }
            if (ticketStream.getRefundModel() != null) {
                DictionaryVo refundDictionary = baseDataFeign.getDictionaryVo(ticketStream.getRefundModel());
                if (refundDictionary != null) {
                    ticketStream.setRefundModel(refundDictionary.getName());
                }
            }

            //设置产品类型为门票类型
            ticketStream.setProductType(TICKET_PRODUCT_CH_NAME);
            return ticketStream;
        }).collect(Collectors.toList());
        return ticketList;
    }

    /**
     * @param pagePo
     * @ClassName: TicketServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.PagePo<com.cloud.drore.eboos.common.entity.supplier.po.TicketQueryPo>
     * @Decription: 设置消费点id到pagePo对象
     * @CreateDate: Created in 2018/1/25 11:15
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    private PagePo<TicketQueryPo> setConsumeToPagePo(PagePo<TicketQueryPo> pagePo) throws BusinessException {
        TicketQueryPo ticketQueryPo = pagePo.getFields();
        if (ticketQueryPo == null) {
            throw new BusinessException(ResultCodeConstant.SERVICE_BUSSNISS_CODE, "参数不能为空!");
        }
        //查询消费点集合
        POIOperation poiOperation = new POIOperation();
        poiOperation.setId(ticketQueryPo.getPoiId());
        List<ConsumeOperation> consumeOperationList = (List<ConsumeOperation>) consumeSupplierApiService.findConsumeList(poiOperation).getData();
        List<Long> consumeIdList = consumeOperationList.stream().map(ConsumeOperation::getId)
                .collect(Collectors.toList());
        //把集合转换成字符串
        String consumeId = StringUtils.join(consumeIdList, ",");
        ticketQueryPo.setConsumeId(consumeId);
        pagePo.setFields(ticketQueryPo);
        return pagePo;
    }

    /**
     * @param ticketInfo
     * @param ticketPrice
     * @ClassName: TicketServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 保存门票信息
     * @CreateDate: Created in 2018/2/9 15:18
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public ResultMessage insertTicket(Ticket ticketInfo, TicketPrice ticketPrice
    ) throws BusinessException {
        ResultMessage rs = new ResultMessage();
        if(!isCodeUnique(ticketInfo.getProductCode()).getIsSuccess()){
            throw new BusinessException(8500,"产品代码已存在！");
        }
        ProductInfoResponseComparePo responseCompareWeb = new ProductInfoResponseComparePo();

        BeanUtils.copyProperties(ticketInfo,responseCompareWeb);
        responseCompareWeb.setProductName(ticketInfo.getName());
        //获取畅游通产品信息
        ResultMessage<ProductInfoResponsePo> synchronizeProduct = synchronizeProduct(ticketInfo.getProductCode());
        ProductInfoResponsePo productInfoResponsePo = synchronizeProduct.getData();
        ProductInfoResponseComparePo productInfoResponseComparePo = new ProductInfoResponseComparePo();
        BeanUtils.copyProperties(productInfoResponsePo,productInfoResponseComparePo);

        if(!responseCompareWeb.equals(productInfoResponseComparePo)){
            throw new BusinessException(8500,"产品信息与畅游通不同步!");
        }
        //复制畅游通同步信息
        BeanUtils.copyProperties(productInfoResponsePo,ticketInfo);
        if(StringUtils.isNotBlank(productInfoResponsePo.getBookAdvanceTime())){
            ticketInfo.setBookAdvanceTime(DateToStringUtil.getTimeShort(productInfoResponsePo.getBookAdvanceTime()));
        }
        //设置待审核状态
        ticketInfo.setStatus(TO_BE_AUDITED);
        //设置默认库存不限
        ticketInfo.setStockMethod(UNLIMITED_STOCK);
        //不收取手续费退款模式不可退
        ticketInfo.setRefundModel(AVAILABLE_FOR_NO_CONSUMPTION);
        ticketInfo.setRefundFee(NO_CHARGES);
        ticketMapper.insertUseGeneratedKeys(ticketInfo);

        //设置产品编号
        POIOperation poiById = consumeSupplierApiService.getPOIById(ticketInfo.getConsumeId());
        if(poiById == null){
            throw new BusinessException(8500,"保存失败，消费点信息有误!");
        }
        ticketInfo.setProductNum(CodingGeneration.getProductGenerationCodingNum(TICKET_PRODUCT,ticketInfo.getId()));
        ticketMapper.updateTicketByParam(ticketInfo);
        //保存验证方式
        saveVerificationCodeTypeAndCollocation(ticketInfo);
        //设置库存和价格门票id并保存(新增时不保存库存)
        if (ticketPrice != null) {
            ticketPrice.setTicketId(ticketInfo.getId());
            ticketPriceMapper.insertUseGeneratedKeys(ticketPrice);
        }

        //保存公共产品数据
        ProductRelation productRelation = new ProductRelation();
        //设置公共产品参数
        productRelation.setProductId(ticketInfo.getId());
        productRelation.setProductCode(ticketInfo.getProductCode());
        productRelation.setCrowd(ticketInfo.getCrowd());
        //设置组合产品类型
        productRelation.setProductType(TICKET_PRODUCT);
        //设置消费点id(添加公共产品消费点关联表)
        productRelation.setConsumeId(String.valueOf(ticketInfo.getConsumeId()));
        productRelation.setProductName(ticketInfo.getName());
        productRelation.setStatus(ticketInfo.getStatus());
        productRelation.setStockMethod(ticketInfo.getStockMethod());
        productRelation.setPaymentType(ticketInfo.getPaymentType());
        productRelation.setRefundModel(ticketInfo.getRefundModel());
        productRelation.setRefundFee(ticketInfo.getRefundFee());
        productRelation.setSupplierSettlementPrice(ticketPrice.getSettlementPrice());
        //设置商户id
        productRelation.setMerchantId(Long.valueOf(LocalData.getCurrentUser().getTypeId()));
        productRelation.setProductNum(ticketInfo.getProductNum());
        //设置实名制
        productRelation.setIsRealName(ticketInfo.getIsRealName());
        productRelation.setInstruction(ticketInfo.getInstruction());
        productRelationMapper.insert(productRelation);
        //更新公共产品id
        ticketInfo.setCommonProductId(productRelation.getId());
        ticketMapper.updateByPrimaryKeySelective(ticketInfo);

        //保存产品消费点关联数据
        ProductConsumeRelation consumeRelation = new ProductConsumeRelation();
        //设置消费点id
        consumeRelation.setConsumeId(ticketInfo.getConsumeId());
        //设置产品id为组合产品id
        consumeRelation.setProduct_id(productRelation.getId());
        //设置商户id
        consumeRelation.setMerchantId(Long.valueOf(LocalData.getCurrentUser().getTypeId()));
        //保存poiId
        POIOperation poiOperation = consumeSupplierApiService.getPOIById(ticketInfo.getConsumeId());
        if (poiOperation != null) {
            consumeRelation.setPoiId(poiOperation.getId());
        }
        productConsumeRelationMapper.insert(consumeRelation);

        if (ticketInfo.getId() == null) {
            throw new BusinessException(BUSINESS_CODE, TICKET_SAVE_FAILURE);
        }
        rs.setId(String.valueOf(ticketInfo.getId()));
        //新增门票后自动关联上所有分销商
        distributorProductAssociationService.setTicketToAllDistributor(productRelation, ticketPrice, ticketInfo);
        return rs;
    }

    //门票验证方式复选框类型保存
    void saveVerificationCodeTypeAndCollocation(Ticket ticketInfo) {
        List<Dictionary> goodsSaleTypeList = iBaseDataFeign.getDicListMapByCode("VERIFYING_CODE_TYPE");
        List<String> dictionaryCode = goodsSaleTypeList.stream().map(Dictionary::getDicCode).collect(Collectors.toList());
        List<String> verificationCodeTypes = ticketInfo.getVerificationType();
        for (String dicCode : dictionaryCode) {
            ProductValidateMethod validateMethod = new ProductValidateMethod();
            validateMethod.setProductType(TICKET_PRODUCT);
            validateMethod.setProductId(ticketInfo.getId());
            validateMethod.setDicCode(dicCode);
            if (verificationCodeTypes.contains(dicCode)) {
                validateMethod.setState(DICTIONARY_STATUS_TRUE);
            } else {
                validateMethod.setState(DICTIONARY_STATUS_FALSE);
            }
            productValidateMethodMapper.insert(validateMethod);
        }

    }

    /**
     * @param ticketInfo
     * @param ticketPrice
     * @param ticketStock
     * @ClassName: TicketServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 更新门票信息
     * @CreateDate: Created in 2018/1/12 10:12
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public ResultMessage updateTicket(Ticket ticketInfo, TicketPrice ticketPrice,
                                      List<TicketStock> ticketStock) throws BusinessException {
        ResultMessage rs = new ResultMessage();
        int result = ticketMapper.updateTicketByParam(ticketInfo);
        updateVerificationCodeType(ticketInfo);

        //设置门票库存
        if (ticketStock != null) {
            for (TicketStock stock : ticketStock) {
                if (stock.getId() != null && stock.getId() != 0) {
                    ticketStockMapper.updateTicketStockByParam(stock);
                } else {
                    stock.setTicketId(ticketInfo.getId());
                    ticketStockMapper.insertUseGeneratedKeys(stock);
                }
            }
        }
        //更新门票价格数据
        if (ticketPrice != null) {
            ticketPriceMapper.updateByPrimaryKey(ticketPrice);
        }
        ProductRelation relation = new ProductRelation();
        relation.setProductId(ticketInfo.getId());
        relation.setProductType(TICKET_PRODUCT);
        relation.setCrowd(ticketInfo.getCrowd());
        relation.setStockMethod(ticketInfo.getStockMethod());
        relation.setPaymentType(ticketInfo.getPaymentType());
        relation.setRefundModel(ticketInfo.getRefundModel());
        //更新公共产品表状态
        relation.setStatus(ticketInfo.getStatus());
        if (ticketPrice != null && ticketPrice.getSettlementPrice() != null) {
            relation.setSupplierSettlementPrice(ticketPrice.getSettlementPrice());
        }
        productRelationMapper.updateProductByParam(relation);
        if (result <= 0) {
            throw new BusinessException(BUSINESS_CODE, TICKET_UPDATE_FAILURE);
        }
        Ticket ticket = ticketMapper.selectByPrimaryKey(ticketInfo.getId());
        //保存库存到redis和每日库存表
        if(UNLIMITED_STOCK.equals(ticket.getStockMethod())){
            productStockService.saveUnlimitedProductStocks(ticket.getCommonProductId(),ticket.getProductNum(),ticket.getTermOfValidityStartTime(),ticket.getTermOfValidityEndTime());
        }else if(CYCLICAL_INVENTORY.equals(ticket.getStockMethod())){
            productStockService.saveTicketProductStocks(ticketStock,ticket.getCommonProductId(),ticket.getProductNum());
        }

        rs.setMessage(TICKET_UPDATE_SUCESS);
        return rs;
    }

    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public ResultMessage updateTicketSupplier(SupplierTicketUpdPo supplierTicketUpdPo) throws BusinessException {
        ResultMessage rs = new ResultMessage();
        Ticket ticket = new Ticket();
        BeanUtils.copyProperties(supplierTicketUpdPo, ticket);
        int result = ticketMapper.updateTicketByParam(ticket);
        updateVerificationCodeType(ticket);

        //更新门票价格数据
        if(supplierTicketUpdPo.getSettlementPrice()!=null){
            TicketPrice price = new TicketPrice();
            price.setTicketId(supplierTicketUpdPo.getId());
            price.setSettlementPrice(supplierTicketUpdPo.getSettlementPrice());
            ticketPriceMapper.updateTicketPriceByTicketId(price);
        }

        //更新公共表信息
        ProductRelation relation = new ProductRelation();
        relation.setProductId(ticket.getId());
        relation.setProductType(TICKET_PRODUCT);
        relation.setSupplierSettlementPrice(supplierTicketUpdPo.getSettlementPrice());
        relation.setCrowd(supplierTicketUpdPo.getCrowd());
        relation.setInstruction(supplierTicketUpdPo.getInstruction());
        relation.setConsumeId(String.valueOf(supplierTicketUpdPo.getConsumeId()));
        productRelationMapper.updateProductByParam(relation);

        Long productId = productRelationMapper.selectIdByTypeAndId(TICKET_PRODUCT, supplierTicketUpdPo.getId());
        ProductConsumeRelation consumeRelation = new ProductConsumeRelation();
        consumeRelation.setProduct_id(productId);
        consumeRelation.setConsumeId(supplierTicketUpdPo.getConsumeId());
        POIOperation poiOperation = consumeSupplierApiService.getPOIById(supplierTicketUpdPo.getConsumeId());
        if (poiOperation != null) {
            consumeRelation.setPoiId(poiOperation.getId());
        }
        productConsumeRelationMapper.updateProductConsumeRelationByParam(consumeRelation);

        if (result <= 0) {
            throw new BusinessException(BUSINESS_CODE, TICKET_UPDATE_FAILURE);
        }

        rs.setMessage(TICKET_UPDATE_SUCESS);
        return rs;
    }

    //修改验证方式复选框属性
    void updateVerificationCodeType(Ticket ticketInfo) {
        ProductValidateMethod validateMethod = new ProductValidateMethod();
        validateMethod.setProductId(ticketInfo.getId());
        validateMethod.setProductType(TICKET_PRODUCT);
        List<ProductValidateMethod> validateMethodDb = productValidateMethodMapper.selectValidateMethodByParam(validateMethod);
        List<String> validateMethodDbCode = validateMethodDb.stream().map(ProductValidateMethod::getDicCode).collect(Collectors.toList());
        List<String> verificationCodeTypeWeb = ticketInfo.getVerificationType();
        if (verificationCodeTypeWeb != null && verificationCodeTypeWeb.size() > 0) {
            for (ProductValidateMethod productValidateMethodDb : validateMethodDb) {
                if (DICTIONARY_STATUS_TRUE.equals(productValidateMethodDb.getState())) {
                    if (!verificationCodeTypeWeb.contains(productValidateMethodDb.getDicCode())) {
                        productValidateMethodDb.setState(DICTIONARY_STATUS_FALSE);
                        productValidateMethodMapper.updateByParam(productValidateMethodDb);
                    }
                } else if (DICTIONARY_STATUS_FALSE.equals(productValidateMethodDb.getState())) {
                    if (verificationCodeTypeWeb.contains(productValidateMethodDb.getDicCode())) {
                        productValidateMethodDb.setState(DICTIONARY_STATUS_TRUE);
                        productValidateMethodMapper.updateByParam(productValidateMethodDb);
                    }
                }
            }
        }
    }

    /**
     * @param ticketId
     * @ClassName: TicketServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 根据id查门票信息 提供分销商接口
     * @CreateDate: Created in 2018/1/16 18:37
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public ResultMessage selectTicketById(Long ticketId) throws BusinessException {
        ResultMessage rs = new ResultMessage();
        TicketAllVo ticketAllVo = ticketMapper.selectTicketById(ticketId);
        if (ticketAllVo == null) {
            throw new BusinessException("该门票信息不存在！");
        }
        DictionaryVo paymentTypeDictionary = iBaseDataFeign.getDictionaryVo(ticketAllVo.getPaymentType());
        DictionaryVo crowdDictionary = iBaseDataFeign.getDictionaryVo(ticketAllVo.getCrowd());
        if (paymentTypeDictionary != null) {
            ticketAllVo.setPaymentType(paymentTypeDictionary == null ? "" : paymentTypeDictionary.getName());
        }
        if (crowdDictionary != null) {
            ticketAllVo.setCrowd(crowdDictionary == null ? "" : crowdDictionary.getName());
        }

        //所属消费点
        ProductConsumeRelation consumeRelation = new ProductConsumeRelation();
        //设置产品id为组合产品id
        if (ticketAllVo.getCommonProductId() == null) {
            rs.setData(ticketAllVo);
            return rs;
        }
        Example productConsumeRelationExample = new Example(ProductConsumeRelation.class);
        Example.Criteria criteria = productConsumeRelationExample.createCriteria();
        criteria.andEqualTo("product_id",ticketAllVo.getCommonProductId());
        List<ProductConsumeRelation> relations = productConsumeRelationMapper.selectByExample(productConsumeRelationExample);
        if (relations != null && relations.size() > 0) {
            consumeRelation = relations.get(0);
        }

        ConsumeOperation consumeOperation = (ConsumeOperation) consumeSupplierApiService.selectByPrimaryKey(consumeRelation.getConsumeId());
        if (consumeOperation != null) {
            ticketAllVo.setConsumeName(consumeOperation.getConsumeName());
            ticketAllVo.setPoiName(consumeOperation.getConsumePoiName());
            ticketAllVo.setPoiId(consumeOperation.getConsumePoiId());
        }
        rs.setData(ticketAllVo);
        return rs;
    }


    /**
     * @param ticketId
     * @ClassName: TicketServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 根据id查门票信息 供应商接口
     * @CreateDate: Created in 2018/1/24 11:55
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public ResultMessage selectTicketByIdSupplier(Long ticketId) throws BusinessException {
        ResultMessage rs = new ResultMessage();
        Ticket ticketInfo = ticketMapper.selectByPrimaryKey(ticketId);
        if (ticketInfo == null) {
            throw new BusinessException(BUSINESS_CODE, TICKET_QUERY_FAILURE);
        }

        DictionaryVo paymentTypeDictionary = iBaseDataFeign.getDictionaryVo(ticketInfo.getPaymentType());
        if (paymentTypeDictionary != null) {
            ticketInfo.setPaymentType(paymentTypeDictionary == null ? "" : paymentTypeDictionary.getName());
        }

        //所属消费点
        ProductConsumeRelation consumeRelation = new ProductConsumeRelation();
        //设置产品id为组合产品id
        consumeRelation.setProduct_id(ticketInfo.getCommonProductId());
        List<ProductConsumeRelation> relations = productConsumeRelationMapper.selectRelationByParam(consumeRelation);
        if (relations != null && relations.size() > 0) {
            consumeRelation = relations.get(0);
        }

        ConsumeOperation consumeOperation = (ConsumeOperation) consumeSupplierApiService.selectByPrimaryKey(consumeRelation.getConsumeId());
        TicketAllVo ticketAllVo = new TicketAllVo();
        //设置验证方式到门票对象
        setVerificationType(ticketInfo);
        BeanUtils.copyProperties(ticketInfo, ticketAllVo);
        if (consumeOperation != null) {
            ticketAllVo.setConsumeName(consumeOperation.getConsumeName());
        }

        //获取门票库存
        TicketStock stock = new TicketStock();
        stock.setTicketId(ticketInfo.getId());
        List<TicketStock> stocks = ticketStockMapper.selectByParam(stock);

        //获取门票库存
        TicketPrice price = new TicketPrice();
        price.setTicketId(ticketInfo.getId());
        price = ticketPriceMapper.selectByParam(price);
        //设置门票信息vo
        TicketVo ticketVo = new TicketVo();
        ticketVo.setTicket(ticketAllVo);
        ticketVo.setTicketPrice(price);
        ticketVo.setTicketStocks(stocks);

        rs.setData(ticketVo);
        return rs;
    }


    //设置验证方式复选框数据到门票产品对象
    void setVerificationType(Ticket ticketInfo) {
        ProductValidateMethod validateMethod = new ProductValidateMethod();
        validateMethod.setProductId(ticketInfo.getId());
        validateMethod.setProductType(TICKET_PRODUCT);
        validateMethod.setState(DICTIONARY_STATUS_TRUE);
        List<ProductValidateMethod> validateMethodDb = productValidateMethodMapper.selectValidateMethodByParam(validateMethod);
        List<String> validateMethodDbCode = new ArrayList<>();
        validateMethodDbCode = validateMethodDb.stream().map(ProductValidateMethod::getDicCode).collect(Collectors.toList());
        ticketInfo.setVerificationType(validateMethodDbCode);

    }

    void setVerificationTypeAllVo(TicketAllVo ticketInfo) {
        ProductValidateMethod validateMethod = new ProductValidateMethod();
        validateMethod.setProductId(ticketInfo.getId());
        validateMethod.setProductType(TICKET_PRODUCT);
        validateMethod.setState(DICTIONARY_STATUS_TRUE);
        List<ProductValidateMethod> validateMethodDb = productValidateMethodMapper.selectValidateMethodByParam(validateMethod);
        List<String> validateMethodDbCode = new ArrayList<>();
        validateMethodDbCode = validateMethodDb.stream().map(ProductValidateMethod::getDicCode).collect(Collectors.toList());
        ticketInfo.setVerificationType(validateMethodDbCode);

    }


    /**
     * @param id
     * @param status
     * @ClassName: TicketServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 上下架门票接口
     * @CreateDate: Created in 2018/1/13 14:38
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Transactional
    public ResultMessage updateStatus(Long id, String status, Long productId) {
        ResultMessage rs = new ResultMessage();
        //设置门票id和上下架状态
        Ticket ticket = new Ticket();
        ticket.setId(id);
        ticket.setStatus(status);
        //更新门票状态
        try {
            int i = ticketMapper.updateTicketByParam(ticket);
            ProductRelation relation = new ProductRelation();
            relation.setProductId(id);
            relation.setProductType(TICKET_PRODUCT);
            relation.setStatus(status);
            productRelationMapper.updateProductByParam(relation);
        } catch (Exception e) {
            logger.error(e.toString());
            rs.setMessage(TICKET_UPDATE_FAILURE);
            rs.setIsSuccess(false);
            return rs;
        }

        rs.setMessage(TICKET_UPDATE_SUCESS);
        // 如果是已发布的状态则表示信息审核通过
        if (status.equals(THE_SHELVES)) {
            //拿到商户的id
            Long merchantId = productRelationMapper.queryMerchantIdByProductId(productId);
            if (null == merchantId || "".equals(merchantId)) {
                throw new RuntimeException("供应算审核触发自动结算失败！");
            } else {
                //设定供应商结算的基本信息
                SupplierSettlementAutoInfoPo supplierSettlementAutoInfoPo = productSupplierSettlementInfo(merchantId);
                int count = supplierSettlementAutoInfoMapper.querySupplierHasBeenSettlement(merchantId);
                if (count <= 0) {
                    supplierSettlementAutoInfoMapper.insert(supplierSettlementAutoInfoPo);
                }
            }
        }
        ticket = ticketMapper.selectByPrimaryKey(id);
        //直接发布时保存库存到redis
        if (THE_SHELVES.equals(status) && UNLIMITED_STOCK.equals(ticket.getStockMethod())) {
            productStockService.saveUnlimitedProductStocks(ticket.getCommonProductId(), ticket.getProductNum(),ticket.getTermOfValidityStartTime(),ticket.getTermOfValidityEndTime());
        }
        //如果下架门票，同步下架包含该门票的组合产品
        if(TO_BE_ON_THE_SHELVES.equals(status)){
            synchronizeCombinationStatus(id);
        }
        return rs;
    }


    /**
     * @param id
     * @ClassName: TicketServiceImpl
     * @Return: com.cloud.drore.eboss.operation.entity.po.SupplierSettlementAutoInfoPo
     * @Decription: 设定供应商结算的基本信息
     * @CreateDate: Created in 2018/3/22 0022 下午 5:41
     * @Author: <a href="410508961@qq.com">夏凯</a>
     * @Modify:
     */
    public SupplierSettlementAutoInfoPo productSupplierSettlementInfo(Long id) {
        SupplierSettlementAutoInfoPo supplierSettlementAutoInfoPo = new SupplierSettlementAutoInfoPo();
        supplierSettlementAutoInfoPo.setSupplierId(id);
        supplierSettlementAutoInfoPo.setSettlementType("线下结算");
        supplierSettlementAutoInfoPo.setSettlementCycle(1);
        //初始化结算的状态
        supplierSettlementAutoInfoPo.setSettlementState(0);
        //第一次结算的时间都是下个月5号
        LocalDate fith = LocalDate.of(LocalDate.now().getYear(), LocalDate.now().getMonth(), 5);
        supplierSettlementAutoInfoPo.setSettlementDate(LocalDateAndDateTransformUtil.localDateToDate(fith.plusMonths(1)));
        return supplierSettlementAutoInfoPo;
    }

    /**
     * @param id
     * @param status
     * @param rejectReason
     * @ClassName: TicketServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 审核驳回门票
     * @CreateDate: Created in 2018/2/1 15:34
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public ResultMessage rejectProduct(Long id, String status, String rejectReason) {
        ResultMessage rs = new ResultMessage();
        //更新门票状态
        try {
            Long commonId = productRelationMapper.selectIdByTypeAndId(TICKET_PRODUCT, id);
            Long userId = Long.valueOf(LocalData.getCurrentUser().getId());
            ProductRejectInfo productRejectInfo = new ProductRejectInfo();
            productRejectInfo.setRejectUserId(userId);
            productRejectInfo.setRejectReason(rejectReason);
            productRejectInfo.setRejectTime(new Date());
            productRejectInfo.setCommonProductId(commonId);
            productRejectInfoMapper.insert(productRejectInfo);
            int i = ticketMapper.rejectProduct(id, status);
            //更新公共表状态
            ProductRelation relation = new ProductRelation();
            relation.setProductId(id);
            relation.setProductType(TICKET_PRODUCT);
            relation.setStatus(status);
            productRelationMapper.updateProductByParam(relation);
        } catch (Exception e) {
            logger.error(e.toString());
            rs.setMessage(TICKET_UPDATE_FAILURE);
            rs.setIsSuccess(false);
            return rs;
        }
        rs.setMessage(TICKET_UPDATE_SUCESS);
        return rs;
    }


    /**
     * @param productNum
     * @ClassName: TicketServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 根据产品编号查门票信息
     * @CreateDate: Created in 2018/3/8 15:37
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public TicketAllVo selectTicketByProNum(String productNum) {
        TicketAllVo ticketAllVo = ticketMapper.selectTicketByProNum(productNum);
        return ticketAllVo;
    }


    @Autowired
    ILoginFeign iLoginFeign;
    /**
     * @param commonId
     * @ClassName: TicketServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 根据公共产品id查驳回原因
     * @CreateDate: Created in 2018/3/9 14:35
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public ResultMessage selectRejectInfoByProId(Long commonId) throws BusinessException {
        if (commonId == null) {
            throw new BusinessException("公共产品id不能为空!");
        }
        ResultMessage resultMessage = new ResultMessage();
        ProductRejectInfoVo productRejectInfo = productRejectInfoMapper.selectRejectInfoByCommonId(commonId);
        if(productRejectInfo == null || productRejectInfo.getRejectUserId() == null){
            resultMessage.setData(new ProductRejectInfoVo());
            return resultMessage;
        }
        ShiroUserVo userVo = iLoginFeign.findById(productRejectInfo.getRejectUserId());
        productRejectInfo.setAccountName(userVo.getName());
        productRejectInfo.setAccountTel(userVo.getPhone());
        resultMessage.setData(productRejectInfo);
        return resultMessage;
    }

    /**
     * @param
     * @ClassName: TicketServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 获取字典信息初始化接口
     * @CreateDate: Created in 2018/1/13 18:05
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public ResultMessage init() {
        DictionaryTicketVo dictionaryTicket = new DictionaryTicketVo();
        //获取产品类型字典信息
        dictionaryTicket.setDictionaryProductType(baseDataFeign.getDicListMapByCodeVo("PRODUCT_TYPE"));
        //获取库存方式字典信息
        dictionaryTicket.setDictionaryStockMethod(baseDataFeign.getDicListMapByCodeVo("INVENTORY_MODE"));
        //获取支付类型字典信息
        dictionaryTicket.setDictionaryPaymentType(baseDataFeign.getDicListMapByCodeVo("PAYMENT_TYPE"));
        //获取产品人群字典信息
        dictionaryTicket.setDictionaryProductCrowd(baseDataFeign.getDicListMapByCodeVo("PRODUCT_CROWD"));
        //获取退款模式字典信息
        dictionaryTicket.setDictionaryRefundModel(baseDataFeign.getDicListMapByCodeVo("REFUND_MODEL"));
        //获取退款手续费字典信息
        dictionaryTicket.setDictionaryRefundFormalities(baseDataFeign.getDicListMapByCodeVo("REFUND_FORMALITIES"));
        //获取验证方式字典信息
        dictionaryTicket.setDictionaryVerifyingCodeType(baseDataFeign.getDicListMapByCodeVo("VERIFYING_CODE_TYPE"));
        //获取消费点列表
        POIOperation poiOperation = new POIOperation();
        //供应商用户时只显示关联的消费点，运营商时显示全部消费点
        if(MERCHANT_SUPPLIER.equals(LocalData.getCurrentUser().getType())){
            poiOperation.setMerchantId(LocalData.getCurrentUser().getTypeId());
            try {
                dictionaryTicket.setConsume((List<ConsumeOperation>) consumeSupplierApiService.findConsumeListBySupplierId(poiOperation).getData());
            } catch (Exception e) {
                logger.error("设置消费点出现异常！");
            }
        }else {
            dictionaryTicket.setConsume((List<ConsumeOperation>) consumeSupplierApiService.findConsumeList(poiOperation).getData());
        }

        //poi列表信息
        dictionaryTicket.setPoiOperation((List<POIOperation>) ipoiSupplierApiService.findByName().getData());
        //供应商列表信息
        dictionaryTicket.setMerchants(merchantSupplierApiService.selectMerchantList());
        //获取产品状态字典信息
        dictionaryTicket.setDictionaryProductStatus(baseDataFeign.getDicListMapByCodeVo("PRODUCT_STATUS"));
        return new ResultMessage(dictionaryTicket);
    }

    /**
     * @param productCode
     * @ClassName: TicketServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage<com.cloud.drore.eboss.supplier.entity.po.ProductInfoResponsePo>
     * @Decription:新增门票输入产品代码同步畅游通产品接口
     * @CreateDate: Created in 2018/3/22 10:04
     * @Author: <a href="1451173193@qq.com">杨亮</a>
     * @Modify:
     */

    public ResultMessage<ProductInfoResponsePo> synchronizeProduct(String productCode) throws BusinessException {
        GetProductByOTARequest req=new GetProductByOTARequest();
        req.setMethod("SINGLE");
        req.setProductCode(productCode);
        ResultMessage<GetProductByOTAResponsePo> rs=getProductFeign.getProductByOTA(req);
        if(ResultCodeConstant.SERVICE_SUCCESS_CODE!=rs.getCode()){
            throw  new BusinessException("产品代码有误请重新填写");
        }
        GetProductByOTAResponsePo po=rs.getData();
        ProductInfoResponsePo resultPo=po.getProductInfos().get(0);
       return new ResultMessage<>(po.getProductInfos().get(0));
    }

    /**
     * @param productCode
     * @ClassName: TicketServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription:
     * @CreateDate: Created in 2018/3/27 11:03
     * @Author: <a href="1451173193@qq.com">杨亮</a>
     * @Modify:
     */
    @Override
    public ResultMessage isCodeUnique(String productCode) throws BusinessException {
        if(productCode==null||productCode.equals("")){
            throw new BusinessException("产品代码不能为空！");
        }
        int count=productRelationMapper.countByCode(productCode);
        if(count==0){
            return ResultMessage.success("ok");
        }
       throw new BusinessException("产品代码已存在！");
    }

    /**
     * @ClassName: TicketServiceImpl
     * @param
     * @Return: void
     * @Decription: 更新已过期的门票状态
     * @CreateDate: Created in 2018/4/12 11:51
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Transactional
    public void updateExpiredTicket() {
        List<TicketAllVo> ticketAllVos = ticketMapper.selectExpiredTicket();
        Ticket ticket = new Ticket();
        ProductRelation relation = new ProductRelation();
        for (TicketAllVo ticketAllVo:ticketAllVos){
            //设置门票id和上下架状态
            ticket.setId(ticketAllVo.getId());
            ticket.setStatus(EXPIRED);
            //更新门票状态
            try {
                ticketMapper.updateTicketByParam(ticket);
                relation.setProductId(ticketAllVo.getId());
                relation.setProductType(TICKET_PRODUCT);
                relation.setStatus(EXPIRED);
                productRelationMapper.updateProductByParam(relation);
            } catch (Exception e) {
                logger.error(e.toString());
            }
        }

    }


    /**
     * @ClassName: TicketServiceImpl
     * @param ticketId
     * @Return: void
     * @Decription: 同步组合产品状态
     * @CreateDate: Created in 2018/4/13 16:48
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    void synchronizeCombinationStatus(Long ticketId){
        List<Long> combinationId = combinationProductRelationMapper.selectCombinationProductIdByTicketId(ticketId);
        for(Long combinationProductId : combinationId){
            //更新组合产品状态
            CombinationProduct combinationProduct = new CombinationProduct();
            combinationProduct.setId(combinationProductId);
            combinationProduct.setStatus(TO_BE_ON_THE_SHELVES);
            combinationProductMapper.updateCombinationProductByParam(combinationProduct);
            //更新组合产品状态
            ProductRelation relation = new ProductRelation();
            relation.setProductId(combinationProductId);
            relation.setProductType(COMBINATION_PRODUCT);
            relation.setStatus(TO_BE_ON_THE_SHELVES);
            productRelationMapper.updateProductByParam(relation);
        }
    }


}
